home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NeXTSTEP 3.1 (Developer) [x86]
/
NeXT Step 3.1 Intel dev.cdr.dmg
/
NextDeveloper
/
Examples
/
SoundAndMusic
/
SoundLibrary
/
chaintest.c
next >
Wrap
Text File
|
1990-10-10
|
2KB
|
79 lines
/*
* chaintest.c - this test shows how to chain sounds together, such that the
* completion of one initiates another.
*/
#import <sound/sound.h>
#import <stdio.h>
#define BUF_SIZE 8192
#define BUF_MAX 8
static int buf_ptr, buf_max;
static SNDSoundStruct *buffers[BUF_MAX];
//
// The termination function gets called when the previously played sound
// completes
//
int end(SNDSoundStruct *s, int tag, int err)
{
if (err) fprintf(stderr,"error while playing sound %d\n",tag);
if (buf_ptr < buf_max) {
err = SNDStartPlaying(buffers[buf_ptr], buf_ptr, 5,0,0,end);
if (err) fprintf(stderr,"cannot start playing %d (%s)\n",buf_ptr,
SNDSoundError(err));
buf_ptr++;
}
}
main (int argc, char *argv[])
{
int size, err, i, j;
int x = 0;
if (argc < 2) {
fprintf(stderr,"usage: chaintest file ...\n");
exit(1);
}
if (argc >= BUF_MAX) {
fprintf(stderr,"too many files (max is %d)\n",BUF_MAX);
exit(1);
}
//
// read the soundfiles into the buffers
//
for (j=1; j<argc; j++) {
err = SNDReadSoundfile(argv[j],&buffers[j]);
if (err) {
fprintf(stderr,"Error : %s\n",SNDSoundError(err));
exit(1);
}
}
//
// Enqueue the first couple of files
//
buf_ptr = 1;
buf_max = argc;
for (j=1; j<3; j++) {
err = SNDStartPlaying(buffers[j],buf_ptr++,5,0,0,end);
if (err) {
fprintf(stderr,"Error : %s\n",SNDSoundError(err));
exit(1);
}
}
//
// wait for everything to complete
//
SNDWait(0);
exit(0);
}